.text:

set %r2, 0x3FFFFFFFF
mov %sp, %r2

movi %r0, 5
call fib

//    mov %at, %sp
//    subi %sp, 6
//    st %at, 0(%sp)
//    st %r0, 2(%sp)
//    st %r1, 3(%sp)
//    st %r2, 4(%sp)
//    st %r3, 5(%sp)
//    set %at, pc+9
//    st %at, 1(%sp)
//    jmp foo

fib:
movi %r0, 0x1FF // %r0 = -1
ld %r1, 2(%sp) //n

// The labels are too far from the current PC and
// therefore we will branch to a closer label and use a jmp which can
// jump with a higher offset.
ble %r1, %r0, onejmp
movi %r0, 2
ble %r1, %r0, twojmp
movi %r0, 29
be %r1, %r0, threejmp
movi %r0, 30
be %r1, %r0, fourjmp
movi %r0, 48
be %r1, %r0, fivejmp
movi %r0, 49
be %r1, %r0, sixjmp

//the fib(n-1) block
movi %r0, 1
sub3 %r0, %r1, %r0
call fib
mov %r2, %rv

//the fib(n-2) block
movi %r0, 2
ld %r1, 2(%sp) //n
sub3 %r0, %r1, %r0
call fib
//return results of fib(n-1) + fib(n-2)
add2 %rv, %r2

return

//jumping block; branch to here to jump to the further labels
onejmp:
	jmp one
twojmp:
	jmp two
threejmp:
	jmp three
fourjmp:
	jmp four
fivejmp:
	jmp five
sixjmp:
	jmp six


six:
set %rv, 0x1CFA62F21 //put 34-bit constant into return register
return

five:
set %rv, 0x11E8D0A40 //put 34-bit constant into return register
return

four:
set %rv, 0xCB228 //put 34-bit constant into return register
return

three:
set %rv, 0x7D8B5 //put 34-bit constant into return register
return

two:
movi %rv, 1 //put 34-bit constant into return register
return

one:
set %rv, 0x3DEADBEEF //put 34-bit constant into return register
return

